<?php

namespace App\Model\Product;

use App\Core\BaseModel;
use EasySwoole\Component\Di;
use EasySwoole\Redis\Redis;

/**
 * CREATE TABLE `ss_goods` (
 * `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
 * `goods_name` varchar(255) NOT NULL COMMENT '商品名称',
 * `goods_url` varchar(255) NOT NULL DEFAULT '' COMMENT '商品链接',
 * `goods_img` varchar(255) NOT NULL COMMENT '商品图片',
 * `goods_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品单价',
 * `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '创建时间',
 * `created_by` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人员账号',
 * `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
 * `updated_by` varchar(32) NOT NULL DEFAULT '' COMMENT '最后更新人员账号',
 * `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除[0:未删除，1：已删除]',
 * `deleted_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '删除时间',
 * PRIMARY KEY (`id`) USING BTREE
 * ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品';
 */
/**
 * Class ProductModel
 * @property int id
 * @property string goods_name
 * @property string goods_url
 * @property string goods_img
 * @property decimal goods_price
 * @property string created_at
 * @property string created_by
 * @property string updated_at
 * @property string updated_by
 * @property int is_delete
 * @property string deleted_at
 * */
class ProductModel extends BaseModel
{

    protected $tableName = 'ss_goods';

    protected $casts = [
        'id' => 'int',
        'goods_name' => 'string',
        'goods_url' => 'string',
        'goods_img' => 'string',
        'goods_price' => 'float',
        'is_delete' => 'int',
        'deleted_at' => 'string',
        'created_at' => 'string',
        'updated_at' => 'string',
        'created_by' => 'string',
        'updated_by' => 'string',
    ];

    protected static function onAfterUpdate($model, $res)
    {
        self::delCache('productCache:');
    }

    protected static function onAfterInsert($model, $res)
    {
        self::delCache('productCache:');
    }
}
